package com.lynn.springboot_demo.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @author cl
 * @Date 2020/5/18 17:30
 * 配置文件工具类
 */
public class PropertiesUtil {

    /**
     * 读取配置文件
     *
     * @param Key
     * @return
     */
    public static String getPropertiesValue(String Key) {
        InputStream is = SolrUtil.class.getClassLoader().getResourceAsStream("config.properties");
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        Properties props = new Properties();
        try {
            props.load(br);
            return (String) props.get(Key);
        } catch (
                IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        String propertiesValue = PropertiesUtil.getPropertiesValue("solr.url");
        System.out.println(propertiesValue);
    }
}
